//
//  JkmpicCollectionView.swift
//  SinaWb
//
//  Created by Jiang on 6/13/16.
//  Copyright © 2016 Jiang. All rights reserved.
//

import UIKit
import SDWebImage
class picCollectionView: UICollectionView,UICollectionViewDataSource,UICollectionViewDelegate{
    var pic_urlArray :[String]?
    var imageCount : Int?
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        self.dataSource = self
        self.delegate = self
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return imageCount ?? 0
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell", forIndexPath: indexPath)
        
        let url = pic_urlArray![indexPath.row]
        
        SDWebImageManager.sharedManager().downloadImageWithURL(NSURL(string: url), options: SDWebImageOptions.init(rawValue: 0), progress: nil) { (image, _, _, _, _) in
            cell.contentView.layer.contents = image.CGImage
            cell.contentView.contentMode = .ScaleAspectFill
            cell.contentView.layer.masksToBounds = true
            
        }
        
        return cell
    }
    


}
